package com.example.consumer.consume;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;


/**
 * @author shuc001
 * @Date 2018/9/27 下午2:18
 */
@Component
public class FastConsumer {


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "fast_q",durable = "true"),
            exchange = @Exchange(value = "fast_ex",type = "topic"),
            key = "fast.#"
    ))
    @RabbitHandler
    public void receive(Message<String> msg, Channel channel) throws IOException {
        System.out.println("迅速消息发送,"+msg.getPayload());
        channel.basicAck((Long) msg.getHeaders().get(AmqpHeaders.DELIVERY_TAG),true);
    }
}
